= render 'backend/shared/financial_year_warning' if Preference.get(:permanent_stock_inventory, true).boolean_value
= kujaku do |k|
  - k.text
  - k.multi_choice :state, [:in_progress, :done, :validated].map{ |s| [s.tl, s] }
  - k.multi_choice :nature, [[:planned.tl(count: 1), :request], [:conducted.tl, :record]]
  - k.helper do
    %label= CultivableZone.model_name.human
    = select_tag :cultivable_zone_id, options_for_select([[]] + CultivableZone.pluck(:name, :id).sort, params[:cultivable_zone_id])
  -# Type of intervention
  - k.helper do
    %label= Intervention.human_attribute_name(:reference_name)
    = select_tag(:procedure_name, options_for_select([[]] + Intervention.used_procedures.collect{|p| [p.human_name, p.name.to_s]}.sort_by(&:first), params[:procedure_name]))
  -# Filter by Activities
  - k.helper do
    %label= Activity.model_name.human
    = select_tag(:activity_id, options_for_select([[]] + Activity.pluck(:name, :id).sort, params[:activity_id]))
  - if current_campaign
    - productions = ActivityProduction.of_campaign(current_campaign)
    - targets = InterventionTarget.joins(:product)
    - if productions && productions.any?
      - k.helper do
        %label= :target.tl
        = select_tag(:product_id, options_for_select([[]] + accented_sort(targets.select(:product_id).distinct.collect{|u| [u.product.work_name, u.product_id]}), params[:product_id]))
  - if InterventionLabelling.any?
    - k.helper do
      %label= Label.model_name.human
      = select_tag(:label_id, options_for_select([[]] + accented_sort(Label.where(id: InterventionLabelling.select(:label_id).uniq).pluck(:name, :id)), params[:label_id].to_i))
  -# Filter by driver
  - k.helper do
    %label= :driver.tl
    = select_tag(:driver_id, options_for_select([[]] + accented_sort(Worker.drivers.pluck(:name, :id)), params[:driver_id]))
  -# Filter by equipment
  - k.helper do
    %label= Equipment.model_name.human
    = select_tag(:equipment_id, options_for_select([[]] + accented_sort(Equipment.pluck(:name, :id)), params[:equipment_id]))

- main_toolbar do |t|
  = t.new(nature: :request, label: :add_intervention_request.tl, params: { redirect: nil })
  = t.new(nature: :record, label: :add_intervention_record.tl, params: { redirect: nil })

- main_period_selector

- if current_campaign
  = janus do |j|
    - j.face :cobbles do

      -# Add content to the main toolbar
      - content_for(:main_toolbar) do
        = label_tag(nil, nil, class: 'compare-planned-realised') do
          = check_box_tag('compare-planned-and-realised', 'false', user_preference_value(User::PREFERENCE_SHOW_COMPARE_REALISED_PLANNED))
          = :compare_planned_and_realised.tl

      - campaign ||= current_campaign

      = taskboard :interventions do |board|

        = modal(id: "taskboard-modal", class: "interventions-modal", size: :large) do
          .modal-body
          .modal-footer


        - edit_icon = content_tag(:i, nil, { :class => "picto picto-long-arrow-right picto--invisible edit-tasks", :title => :change_status_of_selected_interventions.tl })
        - delete_icon = content_tag(:i, nil, { :class => "picto picto-delete picto--invisible delete-tasks", :title => :delete_selected_interventions.tl, data: {confirm: :are_you_sure.tl} })
        - headers_actions = [edit_icon, delete_icon]

        - search_params = params.deep_dup.except(:controller, :action)
        - search_params[:period_interval] = current_period_interval
        - search_params[:period] = current_period

        - header_class = 'taskboard-header--gray'

        - board.column :requests do |column|
          - requested_interventions = Intervention.with_unroll(search_params.merge(nature: :request))
          - column.header :planned.tl(count: requested_interventions[:total_count]) + " (" + requested_interventions[:total_count].to_s + ")", headers_actions, class: header_class
          - add_taskboard_tasks(requested_interventions[:interventions], column)

        - board.column :current do |column|
          - interventions_in_progress = Intervention.with_unroll(search_params.merge(nature: :record, state: :in_progress))
          - column.header :current.tl + " (" + interventions_in_progress[:total_count].to_s + ")", headers_actions, class: header_class
          - add_taskboard_tasks(interventions_in_progress[:interventions], column)

        - board.column :finished do |column|
          - interventions_done = Intervention.with_unroll(search_params.merge(nature: :record, state: :done))
          - column.header :completed.tl + " (" + interventions_done[:total_count].to_s + ")", headers_actions, class: header_class
          - add_taskboard_tasks(interventions_done[:interventions], column)

        - board.column :validated do |column|
          - validated_interventions = Intervention.with_unroll(search_params.merge({ :nature => :record, :state => :validated }))
          - column.header :validated.tl + " (" + validated_interventions[:total_count].to_s + ")", [], class: header_class
          - add_taskboard_tasks(validated_interventions[:interventions], column)


    - j.face :list do
      = main_list
